package com.yanqu.road.dao.impl.log;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.db.DbParameter;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.log.LogWishPoolValue;

import java.sql.Timestamp;
import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 许愿池许愿值日志
 */
public class LogWishPoolValueDaoImpl extends TempDao {

    public boolean addLogWishPoolValueList(List<LogWishPoolValue> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_wish_pool_value(activityId,userId,addValue,totalValue,logTime) VALUES(?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogWishPoolValue data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getAddValue()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getTotalValue()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, new Timestamp(data.getLogTime())));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

}
